package exam.history.huawei02;
// 本题为考试多行输入输出规范示例，无需提交，不计分。
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String[] ops = sc.nextLine().split(" ");

        try {
            List<Integer> pointRecord = new ArrayList<>();
            for(int i = 0; i < ops.length; i++){
                if(Objects.equals(ops[i], "C")){
                    if(pointRecord.size() >= 1){
                        pointRecord.remove(pointRecord.size() - 1);
                    }
                }else if(Objects.equals(ops[i], "D")){
                    pointRecord.add(2 * pointRecord.get(pointRecord.size() - 1));
                }else if(Objects.equals(ops[i], "+")){
                    pointRecord.add(pointRecord.get(pointRecord.size() - 2) + pointRecord.get(pointRecord.size() - 1));
                }else{
                    pointRecord.add(Integer.parseInt(ops[i]));
                }
            }
            int res = 0;
            for (int i = 0; i < pointRecord.size(); i++) {
                res += pointRecord.get(i);
            }
            System.out.println(res);
        }catch (Exception e){
            System.out.println(-1);
        }
    }
}